From 9120178a95d20390e6691c0b6a7f87dabc0bae13 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Sat, 2 Jun 2007 18:33:20 +0000 Subject: [PATCH] garmin_gpi: Split bounds with a new method. --- garmin_gpi.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/garmin_gpi.c b/garmin_gpi.c index 955e9c474..ae6c90da5 100644 --- a/garmin_gpi.c +++ b/garmin_gpi.c @@ -28,6 +28,8 @@ * 2007/05/22: add support for multiple bounding boxes (useful / required!) for large waypoints lists * 2007/05/23: add optional user bitmap + * 2007/06/02: new method to compute center (mean) of bounds + avoid endless loop in group splitting ToDo: @@ -560,17 +562,25 @@ wdata_check(writer_data_t *data) queue *elem, *tmp; double center_lat, center_lon; - if (data->ct <= WAYPOINTS_PER_BLOCK) { - if (data->ct) sortqueue(&data->Q, compare_wpt_cb); + if ((data->ct <= WAYPOINTS_PER_BLOCK) || + /* avoid endless loop for points (more than WAYPOINTS_PER_BLOCK) + at same coordinates */ + ((data->bds.min_lat >= data->bds.max_lat) && (data->bds.min_lon >= data->bds.max_lon))) { + if (data->ct > 1) + sortqueue(&data->Q, compare_wpt_cb); return; } - /* compute the center of current bounds */ - if (data->bds.max_lat == data->bds.min_lat) center_lat = data->bds.max_lat; - else center_lat = (data->bds.max_lat + data->bds.min_lat) / 2; + /* compute the (mean) center of current bounds */ - if (data->bds.max_lon == data->bds.min_lon) center_lon = data->bds.max_lon; - else center_lon = (data->bds.max_lon + data->bds.min_lon) / 2; + center_lat = center_lon = 0; + QUEUE_FOR_EACH(&data->Q, elem, tmp) { + waypoint *wpt = (waypoint *) elem; + center_lat += wpt->latitude; + center_lon += wpt->longitude; + } + center_lat /= data->ct; + center_lon /= data->ct; QUEUE_FOR_EACH(&data->Q, elem, tmp) { waypoint *wpt = (waypoint *) elem; -- 2.30.2